package com.atguigu.test;

import org.apache.http.HttpHost;
import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.action.update.UpdateResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.xcontent.XContentType;

import java.io.IOException;

public class test_es_05_doc_update {

    public static void main(String[] args) throws IOException {

        //创建es客户端
        RestHighLevelClient esClient = new RestHighLevelClient(RestClient.builder(new HttpHost("127.0.0.1",9200,"http")));

        //修改文档对象
        UpdateRequest updateRequest = new UpdateRequest();
        updateRequest.index("user").id("1001");

        updateRequest.doc(XContentType.JSON, "sex","女");

        //修改文档、发送请求
        UpdateResponse updateResponse = esClient.update(updateRequest, RequestOptions.DEFAULT);

        System.out.println("_index: "+updateResponse.getIndex() );
        System.out.println("_id: "+updateResponse.getId());
        System.out.println("_result: "+updateResponse.getResult());

        //关闭es客户端
        esClient.close();
    }
}
